<%@page import="com.wanmait.cookbook.vo.Pager"%>
<%@page import="com.wanmait.cookbook.vo.Userinfo"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%
      String path=request.getContextPath();
    %>
    <ul class="clearfix"  >
<%      
		Userinfo userinfo = (Userinfo)request.getSession().getAttribute("userinfo");
		List<Userinfo> userinfos = (List<Userinfo>)request.getAttribute("userinfos");
//      Userinfo userinfo = (Userinfo)session.getAttribute("userinfo");
      for(int i=0;i<userinfos.size();i++){
        if((i+1)%3!=0){
          %>
        <li class="clearfix user ">
        <input type="hidden" value="<%=userinfos.get(i).getId() %>" class="gzz">
          <div class="left">
            <a href="<%=path %>/PersonalServlet?action=init&id=<%=userinfos.get(i).getId() %>"
              target="_blank" class="user-img" one-link-mark="yes"> <img
              src="<%=path%>/static/image/<%=userinfos.get(i).getAvatar() %>">
            </a> 
            <a href="javascript:void(0)"
              class="fav-btn" 
              data-id="<%=userinfos.get(i).getId()%>" one-link-mark="yes"> 
              <span class="addicon" id="gz<%=userinfos.get(i).getId()%>">＋</span> 关注
              
            </a>
          </div>
          <div class="right">
            <h3>
              <a class="nickname text-lips"
                href="<%=path %>/PersonalServlet?action=init&id=<%=userinfos.get(i).getId() %>"
                one-link-mark="yes"><%=userinfos.get(i).getName() %></a>
            </h3>
            <p class="cate"><%=userinfos.get(i).getTaste() %></p>
            <p>
             简介<%=userinfos.get(i).getInfo() %></p>
          </div>
        </li>
        <%  
          
        }else{
        
      %>

        <li class="clearfix user  three ">
        <input type="hidden" value="<%=userinfos.get(i).getId() %>" class="gzz">
          <div class="left">
            <a href="<%=path %>/PersonalServlet?action=init&id=<%=userinfos.get(i).getId() %>"
              target="_blank" class="user-img" one-link-mark="yes"> <img
              src="<%=path%>/static/image/<%=userinfos.get(i).getAvatar() %>">
            </a> 
            <a href="javascript:void(0)"
              class="fav-btn" 
              data-id="<%=userinfos.get(i).getId()%>" one-link-mark="yes"> 
              <span class="addicon" id="gz<%=userinfos.get(i).getId()%>">＋</span> 关注
              
            </a>
          </div>
<%--           <div class="right">
            <h3>
              <a class="nickname text-lips"
                href="<%=path %>/PersonalServlet?action=init&id=<%=userinfos.get(i).getId() %>"
                one-link-mark="yes"><%=userinfos.get(i).getName() %></a> <a
                class="proicon" href="https://www.douguo.com/user/prodesc"
                target="_blank" one-link-mark="yes"> <img class="proimg"
                src="<%=path%>/static/hotUserinfoShowList_files/2ba3cf1657cbf92e474d7e0534ce8da1.png"
                alt="">
              </a>
            </h3>
            <p class="cate">公司机构</p>
            <p>
             简介<%=userinfos.get(i).getInfo() %></p>
          </div> --%>
        </li>

        <%} }%>
        </ul>
 		<!--显示数字开始  -->
			<div class="pages" id="numbParent">
			
			<%
				Pager pager=(Pager)request.getAttribute("pager");
				int start=1;
				int end=pager.getPageCount();
				if(pager.getPageCount()>5){
					start=pager.getPageNo()-2<1?1:pager.getPageNo()-2;
					end=start+4;
					if(end>pager.getPageCount()){
						end=pager.getPageCount();
						start=end-4;
					}
				}
				%>
				<a id="numb"  href="javascript:void(0);" class="prevPager" one-link-mark="yes">上一页</a>
				<%
				for(int i=start;i<=end;i++){
					if(i==pager.getPageNo()){
						%><a id="numb"  href="javascript:void(0);" style="color:red" class="aliaon" one-link-mark="yes"><%=i %></a>
					<% }else{
						%>
						<a id="numb"  href="javascript:void(0);" class="aliaon" one-link-mark="yes"><%=i %></a>
						<% 
					}
				}
			%>	
			<a id="numb"  href="javascript:void(0);" class="nextPager" one-link-mark="yes">下一页</a>
			<a id="numb"  href="javascript:void(0);" class="aliaon" one-link-mark="yes"><%=pager.getPageNo()%>/<%=pager.getPageCount()%></a>
			
<!-- 上下页事件开始 -->
<script type="text/javascript">
$(function(){
	//上一页点击事件
	$(".prevPager").click(function(){
		var n=<%=pager.getPageNo()%>;
		$.ajax({
			url:"<%=path%>/UserInfoServlet",
			data:{action:"showPagerFansUser",pageNo:n-1},
			success:function(mes){
				$("#hotUserinfoShow").html(mes);
			}
			
		});
	});
	//下一页点击事件
	$(".nextPager").click(function(){
		var n=<%=pager.getPageNo()%>;
		$.ajax({
			url:"<%=path%>/UserInfoServlet",
			data:{action:"showPagerFansUser",pageNo:n+1},
			success:function(mes){
				$("#hotUserinfoShow").html(mes);
			}
			
		});
	});

})
</script>	
<!--上下页事件结束  -->			
					
			</div>		
			
			<!--显示数字结束  -->
<script>
if(<%=userinfo!=null%>){
  $(".gzz").each(function(){
    var aid = $(this).val();
    $.ajax({
      url:"<%=path%>/AttentionServlet",
      data:{action:"judgeAttention",authorId:aid},
      success:function(msg){
        if(msg=="true"){
            $("#gz"+aid+"").text("已");
          }
          else{
            $("#gz"+aid+"").text("＋");
          }
      }
    });
  });
  $(".fav-btn").click(function(){
    var aid =$(this).data("id");
    if($("#gz"+aid+"").text()=="＋"){
      $.ajax({
        url:"<%=path%>/AttentionServlet",
        data:{action:"addAttention",authorId:aid}
      });
      $("#gz"+aid+"").text("已");
    }
    else{
      if(!window.confirm("确定取消关注？")){
        return;
      }
      $.ajax({
        url:"<%=path%>/AttentionServlet",
        data:{action:"cancelAttention",authorId:aid}
      });
      $("#gz"+aid+"").text("＋");
    }
     
  });
}
else{
  $(".fav-btn").click(function(){
    var aid =$(this).data("id");
    $.ajax({
      url:"<%=path%>/AttentionServlet",
      data:{action:"addAttention",authorId:aid},
      success:function(msg){
        if("no"==msg){
          window.location.href="<%=path%>/login.jsp";
        }
      }
    }); 
  });
}
</script>